package com.example.lock.redission;

import com.example.lock.DistributedLock;
import com.example.lock.redisLock.BaseJedisClusterLock;
import org.apache.commons.lang3.StringUtils;
import org.redisson.Redisson;
import org.redisson.api.RLock;
import org.redisson.api.RedissonClient;
import org.redisson.config.ClusterServersConfig;
import org.redisson.config.Config;

import java.util.concurrent.CyclicBarrier;
import java.util.concurrent.TimeUnit;

/**
 * @program:
 * @description:
 * @author: liguanfu
 * @create: 2021-06-01 14:12
 **/
public class BaseRedissonLock {
    protected static RedissonClient redissonClient ;


    static {
        Config config = new Config();
        config.useClusterServers()
                         .setScanInterval(2000)
                         .addNodeAddress("redis://127.0.0.1:7000")
                         .addNodeAddress("redis://127.0.0.1:7001")
                         .addNodeAddress("redis://127.0.0.1:7002")
                         .addNodeAddress("redis://127.0.0.1:7003")
                         .addNodeAddress("redis://127.0.0.1:7004")
                         .addNodeAddress("redis://127.0.0.1:7005");
         redissonClient = Redisson.create(config);

    }








    public String acquireLock(String lockName, Long acquireTime, Long expireTime) throws Exception {
        RLock lock = redissonClient.getLock(lockName);
        lock.lock(expireTime,TimeUnit.SECONDS);

        return null;
    }


    public String acquireLock(String lockName, Long time, TimeUnit unit) throws Exception {
        return null;
    }


    public void release(String lockName, String identify) throws Exception {

    }


    public Boolean extendLockTime(String lockName, Long time, String identify) {
        return null;
    }

    public static void main(String[] args) {

        RLock lock1 = BaseRedissonLock.redissonClient.getLock("lock1");
        RLock lock2 = BaseRedissonLock.redissonClient.getLock("lock2");
        RLock lock3 = BaseRedissonLock.redissonClient.getLock("lock3");

        RLock hellolock = BaseRedissonLock.redissonClient.getRedLock(lock1,lock2,lock3);
        hellolock.lock(30L,TimeUnit.MINUTES);


    }

}

